#include "sprite.h"
#include "core.h"

sprite::sprite(float _x,float _y,float _z,float _w,float _h,texture* _tex,float _tu,float _tv,float _tw,float _th,color _clr)
{
	x=_x;
	y=_y;
	z=_z;
	w=_w;
	h=_h;
	tu=_tu;
	tv=_tv;
	tw=_tw;
	th=_th;

	if(_tex)
	{
		tw *= w/_tex->m_width;
		th *= h/_tex->m_height;
	}

	clr=_clr;
	tex=_tex;

	m_render = core::get_inst().get_render();
}

sprite::sprite()
{
	x=y=z=w=h=tu=tw = 0;
	clr=color(1.0f,1.0f,1.0f,1.0f);
	tex = 0;

	m_render = core::get_inst().get_render();
}

void sprite::draw()
{
	m_render->set_cullmode(cullmode_none);

	/*
	D3DCHECK(m_render->get_device()->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
	
	sprite_vrt vrt []={{x,   y+h, z,1.0f,clr.argb(),tu,	   tv+th},
					   {x,   y,	  z,1.0f,clr.argb(),tu,	   tv	},
					   {x+w, y+h, z,1.0f,clr.argb(),tu+tw, tv+th},
					   {x+w, y,	  z,1.0f,clr.argb(),tu+tw, tv	}};

	m_render->set_texture(0,tex);
	D3DCHECK(m_render->get_device()->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1));
	D3DCHECK(m_render->get_device()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,vrt,sizeof(sprite_vrt)));
	*/
}